package com.mygo.caseDemo.randomLottery_D1;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;

/**
 * @author XMG
 */
public class RandomLottery {

    /**
     * 对学生年龄进行排序
     */
    public static void main(String[] args) {
        Student s1 = new Student.Builder()
                .setName("jack")
                .setAge(18)
                .build();
        Student s2 = new Student.Builder()
                .setName("tom")
                .setAge(21)
                .build();
        Student s3 = new Student.Builder()
                .setName("jerry")
                .setAge(15)
                .build();
        Student s4 = new Student("zs",24);
        Student s5 = new Student();
        s5.setName("ls");
        s5.setAge(19);
        String s ;
        List<Student> students = new ArrayList<>(){

        };
        students.add(s1);
        students.add(s2);
        students.add(s3);
        students.add(s4);
        students.add(s5);
        System.err.println("未排序前集合");
        students.forEach(System.err::println);
        //通过stream流对学生年龄从大到小排序
        System.err.println("对学生年龄从大到小排序");
        students.stream().sorted((o1, o2) -> o2.getAge() - o1.getAge()).forEach(System.err::println);
        //通过stream流对学生年龄从小到大排序
        System.err.println("对学生年龄从小到大排序");
        students.stream().sorted(Comparator.comparingInt(Student::getAge)).forEach(System.err::println);

    }
}
